package com.groupbuying.payproducer.controller;

import com.groupbuying.payproducer.service.PayResultService;
import com.groupbuying.payproducer.utils.apiresult.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 支付结果
 *
 * @author zmlmagic
 * @email zmlmagic@163.com
 * @date 2019-05-10 02:12:56
 */

@RestController
@RequestMapping("/payResult")
public class PayResultController {

    @Autowired
    private PayResultService payResultService;

    /**
     * @api {post} /payResult/changeAndShowPayInfo 查询支付成功信息
     * @apiDescription 支付完成,返回支付成功信息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} paramMap 参数描述详情：{payId:支付单id}
     * @apiSuccess {JSON} ApiResult 成功返回结果:{cost:消费金额,orderId:订单id,intergral:积分变动,payCurrency:实付积分}
     * @apiError {JSON} ApiResult 错误信息 code,错误提示
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar
     */
    @PostMapping("/changeAndShowPayInfo")
    public ApiResult changeAndShowPayInfo(@RequestParam Map paramMap) {
        return payResultService.payDealForSuc(paramMap);
    }

    /**
     * @api {post} /payResult/currencyPayCallBack 积分异步
     * @apiDescription 积分异步通知处理接口
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} requestParam 参数描述详情：{currencyCode:积分支付code,message:信息,payCurrency:支付积分,orderNum:订单id}
     * @apiSuccess {JSON} String success
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar 积分中心
     */
    @PostMapping("/currencyPayCallBack")
    public String currencyPayCallBack(@RequestParam Map<String,Object> requestParam) {
        return payResultService.currencyPaymentCallback(requestParam);
    }

    /**
     * @api {post} /payResult/balancePayCallBack 余额异步
     * @apiDescription 积分异步通知处理接口
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} requestParam 参数描述详情：{balanceCode:余额支付code,message:信息,payMoney:支付余额,orderNum:订单id}
     * @apiSuccess {JSON} String success
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar 余额中心
     */
    @PostMapping("/balancePayCallBack")
    public String balancePayCallBack(@RequestParam Map<String,Object> requestParam) {
        return payResultService.balancePaymentCallback(requestParam);
    }

    /**
     * @api {post} /payResult/weChatPayCallBack 微信原生异步
     * @apiDescription 原生微信异步通知处理接口
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {HttpServletRequest} request 参数描述详情：{appid:服务商的APPID,mch_id:商户号,sub_appid:子商户号,device_info:设备号,is_subscribe:是否关注公众账号,nonce_str:随机字符串,sub_is_subscribe:是否关注子公众账号,sign:签名,result_code:业务结果,err_code:错误代码,err_code_des:错误代码描述,openid:用户标识,sub_openid:用户子标识,trade_type:交易类型,bank_type:付款银行,total_fee:总金额,fee_type:货币种类,cash_fee:现金支付金额,cash_fee_type:现金支付货币类型,settlement_total_fee:应结订单金额,coupon_fee:代金券金额,coupon_count:代金券使用数量,coupon_type_$n:代金券类型,coupon_id_$n:代金券ID,coupon_fee_$n:单个代金券支付金额,transaction_id:微信支付订单号,out_trade_no:商户订单号,attach:商家数据包,time_end:支付完成时间}
     * @apiSuccess {JSON} String {return_code:SUCCESS,return_msg:OK}
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar 微信平台
     */
    @PostMapping("/weChatPayCallBack")
    public String weChatPayCallBack(HttpServletRequest request) {
        return payResultService.weChatPaymentCallback(request);
    }

    /**
     * @api {post} /payResult/aliPayCallBack 支付宝原生异步
     * @apiDescription 原生支付宝异步通知处理接口
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} requestParams 参数描述详情：{notify_time:通知时间,notify_type:通知类型,notify_id:通知校验ID,app_id:支付宝分配给开发者的应用Id,charset:编码格式,version:接口版本,sign_type:签名类型,sign:签名,trade_no:支付宝交易号,out_trade_no:商户订单号,out_biz_no:商户业务号,buyer_id:买家支付宝用户号,buyer_logon_id:买家支付宝账号,seller_id:卖家支付宝用户号,seller_email:卖家支付宝账号,trade_status:交易状态,total_amount:订单金额,receipt_amount:	实收金额,invoice_amount:开票金额,buyer_pay_amount:付款金额,point_amount:集分宝金额,refund_fee:总退款金额,subject:订单标题,body:商品描述,gmt_create:交易创建时间,gmt_payment:交易付款时间,gmt_refund:交易退款时间,gmt_close:交易结束时间,fund_bill_list:支付金额信息,passback_params:回传参数,voucher_detail_list:优惠券信息}
     * @apiSuccess {JSON} String success
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar
     */
    @PostMapping("/aliPayCallBack")
    public String aliPayCallBack(@RequestParam Map<String,String> requestParams) {
        return payResultService.aliPaymentCallback(requestParams);
    }

    /**
     * @api {get} /payResult/getInfoForCurrencyWeChatRemind 查询微信推送消息
     * @apiDescription 根据支付单ID查询推送微信通知的消息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} id 支付单ID
     * @apiSuccess {JSON} Map 成功返回结果:{shopName:商户名称,formId:formId,orderId:订单id,payTime:支付时间,payMoney:支付金额}
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar API内部调用
     */
    @GetMapping("/getInfoForCurrencyWeChatRemind")
    public Map<String,String> getInfoForCurrencyWeChatRemind(String id){
       return payResultService.getInfoForCurrencyWeChatRemind(id);
    }

    /**
     * @api {get} /payResult/getInfoForCurrencyWeChatRemind 获取订单信息
     * @apiDescription 给积分中心使用，通过支付单号查询门店名称，积分支付类型，订单号
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} id 支付单ID
     * @apiSuccess {JSON} Map 成功返回结果:
     * @apiError {JSON} Map 错误信息 code,错误提示
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar API内部调用
     */
    @GetMapping("/getOrderInfoCounterNameCurrencyType")
    public Map<String,String> getOrderInfoCounterNameCurrencyType(String payId){
        return payResultService.getOrderInfoCounterNameCurrencyType(payId);
    }
}
